package net.thxjj.mobileServer.service.impl;

import net.thxjj.mobileServer.dao.UaaDao;
import net.thxjj.mobileServer.service.ISendEmailService;
import net.thxjj.mobileServer.util.SendMail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class SendEmailService implements ISendEmailService {

    private final int MAX_SEND_EMAIL_CODE = 5;


    @Autowired
    private UaaDao uaaDao;

    @Async("taskExecutor")
    @Override
    public void sendRegisterVerifyCode(String email, String code) {
        String smtp = "smtp.163.com";
        String from = "tracyhenryduck@163.com";
        String subject = "SiterWell验证码";
        String username="tracyhenryduck@163.com";
        String password="MVNHBEUASDKGHROM";
        SendMail.send(smtp, from, email, subject, code, username, password,1);
    }

    @Async("taskExecutor")
    @Override
    public void sendResetVerifyCode(String email, String code) {
        String smtp = "smtp.163.com";
        String from = "tracyhenryduck@163.com";
        String subject = "SiterWell验证码";
        String username="tracyhenryduck@163.com";
        String password="MVNHBEUASDKGHROM";
        SendMail.send(smtp, from, email, subject, code, username, password,2);
    }

    @Override
    public boolean checkMultipleSending(String sessionId){
       long count =  uaaDao.getCoumntOfSessionEmailCode(sessionId);
       return count >= MAX_SEND_EMAIL_CODE;
    }
}
